package com.wyvoid.forum.dao.hibernate;

import com.wyvoid.core.persistent.hibernate.HibernateDAO;
import com.wyvoid.core.persistent.hibernate.HibernatePage;
import com.wyvoid.core.persistent.Pagination;
import com.wyvoid.forum.dao.IMessageDAO;
import com.wyvoid.forum.domain.Message;

/**
 * 消息Hibernate数据处理实现
 *
 * @author wyvoid
 * @version $Revision: 1.11 $ $Date: 2006/06/18 14:27:05 $
 * @link www.wyvoid.com
 */
public class MessageDAO extends HibernateDAO<Message> implements IMessageDAO {

    public HibernatePage getMySendMessages(long sendUserId, Pagination pagination) {
        String hql="from Message m where m.sendUserId=? and m.deleteBySender=false and m.type!=-1";
        return doQuery(hql,true,pagination,sendUserId);
    }

    public HibernatePage getMyMessages(long receiverId, Pagination pagination) {
        String hql = "from Message m where m.receiveUserId=? and m.deleteByReceiver=false and m.type!=-1";
        return doQuery(hql, true, pagination, receiverId);
    }

    public HibernatePage getTrashMessages(long userId, Pagination pagination) {
       String hql="from Message m where (m.sendUserId=? and m.deleteBySender=true) or (m.receiveUserId=? and m.deleteByReceiver=true)";
        return doQuery(hql,true,pagination,userId,userId);
    }

    public HibernatePage getDraftMessages(int status, long sendUserId, Pagination pagination) {
       String hql = "from Message m where m.type=? and m.sendUserId=? and m.deleteBySender=false";
        return doQuery(hql, true, pagination, status, sendUserId);
    }
}